package com.example.save;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.fragment.app.Fragment;


public class fragment4 extends Fragment {

    private static final String FILE_NAME = "Qfile";
    private Button button;




    public fragment4(){
        super(R.layout.fragment4);
    }

    @Override
    public void onViewCreated( View view,Bundle savedStanceState){
        super.onViewCreated(view,savedStanceState);

        button=getActivity().findViewById(R.id.button2);
        final EditText username=getActivity().findViewById(R.id.editTextTextPersonName);
        final EditText password=getActivity().findViewById(R.id.editTextTextPersonName2);
        final SharedPreferences settings=getActivity().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);



        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String shapassword= sha256.getSHA256(password.getText().toString());//获取加密报文

                SharedPreferences.Editor editor=settings.edit();

                editor.putString("name",username.getText().toString());

                editor.putString("num",shapassword);

                editor.commit();

                Toast.makeText(getActivity(),"保存成功",Toast.LENGTH_SHORT).show();



            }
        });

            String name = settings.getString("name", "");
            String num = settings.getString("num", "");
            username.setText(name);
            password.setText(num);

    }
}
